package com.rhb.af.web.struts.form;

import java.util.Iterator;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.beanutils.PropertyUtils;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.DynaActionForm;

import com.rhb.ca.web.util.HttpConnect;


public class BaseDynaActionForm extends DynaActionForm {

	public void reset(ActionMapping mapping, HttpServletRequest request){
		//System.out.println("********** BaseDynaActionForm reset()");
		try{
			if(PropertyUtils.isWriteable(this, "user")){
				PropertyUtils.setProperty(this, "user", HttpConnect.getUzer(request));
			}
			
			Iterator i = this.getMap().keySet().iterator();
			while(i.hasNext()){
				String fieldName = (String)i.next();
				if(fieldName.indexOf(".")!=-1){
					String initial = this.getString(fieldName);
					if(initial.indexOf(".")==-1){
						PropertyUtils.setProperty(this, fieldName, initial);	
					}else{
						PropertyUtils.setProperty(this, fieldName, (String)PropertyUtils.getProperty(this,initial));						
					}
				}
			}
		}catch(Exception e){e.printStackTrace();}

	}
}